package cn.edu.hznu.util.socket.tcp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

public class Client {
	
	public static void main(String[] args) {
		try {
			Socket client = new Socket("127.0.0.1", 3000);
			client.setSoTimeout(10000);
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			PrintStream out = new PrintStream(client.getOutputStream());
			BufferedReader bufFromServer = new BufferedReader(new InputStreamReader(client.getInputStream()));
			boolean flag = true;
			while (flag) {
				System.out.println("Input message: ");
				String str = input.readLine();
				out.println(str);
				if (str.equals("bye")) {
					flag = false;
				} else {
					String echo = bufFromServer.readLine();
					System.out.println(echo);
				}
					
			}
			input.close();
			if (null != client) {
				client.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
